#!C:\Python\Python36\Python.exe
# -*- coding:utf-8 -*-
#@Time  : 2019-12-19 15:46
#@Author: iceman
#@File  : exesql.py
import pymysql

class GetSql():

    def __init__(self,sql):
        self.sql = sql
        self.flag = 0
    def getlogin(self):
        try:
            conn = pymysql.connect(
                host = "127.0.0.1",
                port = 3306,
                user = "root",
                passwd = "root",
                db = "test",
                charset = "utf8"
            )
            mycursor = conn.cursor()
            mycursor.execute(self.sql)
            mycursor.close()
            # 数据表内容有更新，必须使用到该语句
            conn.commit()
            # 关闭连接
            conn.close()
            print("Content-type:text/html")
            print()
            print('<html>')
            print('<head>')
            print('<meta charset="gb2312">')
            print('</head>')
            print('<body>')
            print("<h2>提交成功</h2>")
            print('flag:' + str(self.flag))
            print('</body>')
            print('</html>')
            self.flag = 1
        except pymysql.Error as e:
            print("mysql error is %d:%s" %(e.args[0],e.args[1]))

